//
//  StrategyModel.swift
//  travelMap
//
//  Created by green on 15/6/23.
//  Copyright (c) 2015年 com.city8. All rights reserved.
//

import ReactiveCocoa
import JSONHelper
import SwiftDate

// 攻略信息
public class StrategyModel: NSObject, Deserializable {
   
    var strategyId      : String?               // 攻略ID
    var picUrl          : NSURL?                // 攻略配图地址
    var title           : String?               // 攻略名称
    var createTime      : NSDate=NSDate()       // 创建时间 YYYY-MM-dd
    var visitNumber     : Int = random()%1000   // 浏览次数
    var author          : String?               // 小编
    var authorPicUrl    : NSURL?                // 小编头像
    var desc            : String?               // 简介
    var likeNumber      : Int = random()%1000   // 喜欢人数
    var strategyThemes  : [String]?             // 攻略主题
    var strategyMonths  : [String]?             // 攻略使用的月份
    var strategyType    : String?               // 攻略类型
    
    var strategyPhotoInfo: PhotoInfo?
    var authorPhotoInfo: PhotoInfo?
    
    override init() {}
    
    required public init(data : [String:AnyObject]) {
        
        strategyId      <-- data["articleId"]
        picUrl          <-- data["picUrl"]
        title           <-- data["title"]
        createTime      <-- (data["createTime"], "yyyy-MM-dd HH:mm:ss")
        visitNumber     <-- data["visitCount"]
        author          <-- data["author"]?["Name"]
        authorPicUrl    <-- data["author"]?["Img"]
        desc            <-- data["desc"]
        likeNumber      <-- data["likeCount"]
        
        if let picUrl=picUrl {
            
            strategyPhotoInfo = PhotoInfo(sourceImageURL: picUrl)
        }
        
        if let authorPicUrl=authorPicUrl {
            
            authorPhotoInfo = PhotoInfo(sourceImageURL: authorPicUrl)
        }
    
    }
    
    override public var description: String {
        
        get {
            
            let createTimeStr = createTime.toString(format: DateFormat.Custom("yyyy-MM-dd HH:mm:ss"))
            
            return "strategyId:\(strategyId) \n picUrl:\(picUrl) \n title:\(title) \n createTime:\(createTimeStr) \n visitNumber:\(visitNumber) \n author:\(author) \n authorPicUrl:\(authorPicUrl) \n desc:\(desc) \n likeNumber:\(likeNumber) \n strategyPhotoInfo:\(strategyPhotoInfo) \n authorPhotoInfo:\(authorPhotoInfo) \n --------------------------------------------------------------------- \n "
        }
    }
}
